#!/bin/bash
PACKAGE_NAME=arprec
MAJOR_VERSION=2
MINOR_VERSION=2
PATCH_LEVEL=$1
if [[ -z "$PATCH_LEVEL" ]]; then
  echo "Usage: makedist.sh patch-level"
  exit
fi

VERSION=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_LEVEL
echo "Creating $PACKAGE_NAME-$VERSION distribution..."

if [ -z "$CXX" ]; then
  export CXX=g++
fi
if [ -z "$FC" ]; then
  export FC=gfortran
fi

DIR=/var/tmp/$PACKAGE_NAME-$$
ORIG_DIR=`pwd`

mkdir -p $DIR &&
cp -rp . $DIR &&
cd $DIR &&
mv configure.ac configure.old &&
sed "/^define(\[ARPREC_PATCHLEVEL\]/s/devel/$PATCH_LEVEL/" configure.old >configure.ac && 
rm -f configure.old &&
config/autogen.sh &&
./configure &&
git log --no-merges >ChangeLog &&
make distcheck &&
cp $PACKAGE_NAME-$VERSION.tar.gz $ORIG_DIR &&
rm -rf $DIR

